package com.exercises;

class Exercise413 {
    public static void main(String[] args) {
        System.out.println(numberOfArithmeticSlices(new int[]{1, 2, 3, 4}));
    }


    public static int numberOfArithmeticSlices(int[] nums) {
        int n = nums.length;
        if (n < 3) return 0;
        int[] dp = new int[n + 1];
        for (int i = 2; i < n; i++) {
            if (nums[i] - nums[i - 1] == nums[i - 1] - nums[i - 2]) {
                dp[i] += 1;
                dp[i] += dp[i - 1];
            }
        }
        int sum = 0;
        for (int num : dp) {
            sum += num;
        }
        return sum;
    }
}
